package org.lyp.action;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;

import org.lyp.action.BaseAction;
import org.lyp.action.Json;
import org.lyp.util.ExceptionUtil;
import org.lyp.vo.Member;
import org.lyp.service.MemberService;
/**
 * 客户控制器 MemberAction
 * @author DCJ
 *
 */
@Controller
@Action(value = "member", results = { @Result(name = "member", location = "/member.jsp") })
public class MemberAction extends BaseAction implements ModelDriven<Member> {
	private static final long serialVersionUID = 3088843221530537631L;
	private static final Logger logger = Logger.getLogger(MemberAction.class);
	@Autowired
	private MemberService memberService;
	public Member member = new Member();
	/**
	 * 得到数据列表
	 */
	public void grid(){
		int total = memberService.getTotal();
		List<Member> list = memberService.findAllMember(page, rows, sort, order);		
		writeJson(total,list);
	}
	/**
	 * 添加操作
	 */
	public void add(){
			Json result = new Json();
			try {
				memberService.saveMember(member);
				result.setSuccess(true);
				result.setMsg("添加客户成功");					
			} catch (Exception e) {
				logger.debug(ExceptionUtil.getExceptionMessage(e));
				result.setMsg("添加客户失败");					
			}
			writeJson(result);
	}
	/**
	 * 修改操作
	 */
	public void edit() {
			Json result = new Json();
			try {
				memberService.updateMember(member);
				result.setSuccess(true);
				result.setMsg("修改客户成功");
				result.setSuccess(true);
			} catch (Exception e) {
				logger.debug(ExceptionUtil.getExceptionMessage(e));
				result.setMsg("修改客户失败");
			}
			writeJson(result);
	}
	/**
	 * 删除操作
	 */
	public void remove() {
			Json result = new Json();
			try {
				memberService.deleteMember(member.getMemID());
				result.setSuccess(true);
				result.setMsg("删除客户成功");
			} catch (Exception e) {
				logger.debug(ExceptionUtil.getExceptionMessage(e));
				result.setMsg("删除客户失败");
			}
			writeJson(result);
	}
	@Override
	public Member getModel() {
		return member;
	}	
}
